<template>
  <div>
    <v-header :seller="seller"></v-header>
    <div class="tab border-1px">
      <div class="tab-item">
        <router-link to="/goods">商品</router-link>
      </div>
      <div class="tab-item">
        <router-link to="/ratings">评论</router-link>
      </div>
      <div class="tab-item">
        <router-link to="/seller">商家</router-link>
      </div>
    </div>
    <!-- 路由匹配到的组件将渲染在这里.router-view也可以像普通组件那样传递数据 -->
    <keep-alive>
      <router-view :seller="seller"></router-view>
    </keep-alive>
  </div>
</template>

<script>
  import VHeader from './components/header/header';
  import { urlParse } from 'common/js/util';

  const ERR_OK = 0;
  //  const ERR_FAIL = 1;

  export default{
    data() {
      return {
        seller: {
          id: (() => {
            let queryParam = urlParse();
//            console.log(queryParam);
            return queryParam.id;
          })()
        }
      };
    },
    created() {
      this.$http.get('/api/seller?id=' + this.seller.id).then(
        response => {
          response = response.body;
          if (response.errno === ERR_OK) {
//            this.seller = response.seller;
            console.log('1:' + this.seller.id);       // data里定义的seller对象有id属性
            console.log('2:' + response.seller.id);   // 服务端返回的对象无id属性
            // 通过Vue提供的Object.assign(arg1,arg2,arg3) 方法扩展属性
            // arg1: 目标对象,  arg2: 基准对象(在它的基础上扩展), arg3: 扩展对象(将它的属性添加到基准对象上)
            this.seller = Object.assign({}, this.seller, response.seller);
            console.log('id:' + this.seller.id);
          }
        }
      );
    },
    methods: {
      ulrParse() {

      }
    },
    components: {
      // header与H5中的原生的header标签冲突故这里起一个别名v-header.
      'v-header': VHeader
    }
  };
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import "./common/stylus/mixin.styl"

  .tab
    display: flex
    width: 100%
    height: 40px
    line-height: 40px
    border-1px(rgba(7, 17, 27, 0.1))
    .tab-item
      flex: 1
      text-align: center
      & > a
        display: block
        font-size: 14px
        color: rgb(77, 85, 93)
        &.active
          color: rgb(240, 20, 20)

</style>
